package dao

import (
	"dbManager/example/engine"
	"dbManager/example/model"
	"log"

	"github.com/zhuxiujia/GoMybatis"
	"github.com/zhuxiujia/GoMybatis/tx"
)

type MonitorMapper struct {
	GoMybatis.SessionSupport
	FindAll         func(session *GoMybatis.Session) ([]model.Monitor, error)
	Insert          func(session *GoMybatis.Session, arg model.Monitor) (int64, error)   `args:"session,arg"`
	FindById        func(session *GoMybatis.Session, id int) ([]model.Monitor, error)    `args:"session,id"`
	DeleteByLogic   func(session *GoMybatis.Session, id int, version int) (int64, error) `args:"session,id,version"`
	DeleteByPhysics func(session *GoMybatis.Session, id int, version int) (int64, error) `args:"session,id,version"`
	UpdateById      func(session *GoMybatis.Session, arg model.Monitor) (int64, error)   `args:"session,arg"`
}

func (monitorMapper MonitorMapper) Method() {

}
func NewMonitorMapper() *MonitorMapper {
	return &MonitorMapper{}
}

var GMonitorMapper = NewMonitorMapper()

func init() {
	engine.DB.DbManager.LoadXmlMapper(GMonitorMapper)
	var err error
	engine.DB.Session, err = GMonitorMapper.SessionSupport.NewSession()
	if err != nil {
		log.Fatal(err, "事务创建失败")
	}
	p := tx.PROPAGATION_REQUIRED
	err = engine.DB.Session.Begin(&p)
	if err != nil {
		log.Println("事务开启失败")
	}
}
